#!/usr/bin/python3
# -*-coding:utf-8 -*-
"""
自动一个dict类，用这个类定义的dict可以通过属性访问
>>> d = Dict(a=1, b=2)
>>> d['a']
1
>>> d.a
1
"""


class Dict(dict):

    def __init__(self, **kw):
        super(Dict, self).__init__(**kw)

    def __getattr__(self, key):
        try:
            return self[key]
        except KeyError:
            # print(e)
            # print(r"'Dict' object has no attribute '%s'" % key)
            raise AttributeError(r"'Dict' object has no attribute '%s'" % key)

    def __setattr__(self, key, value):
        self[key] = value
